//
//  TBRNameSettingC.m
//  TBRentClient
//
//  Created by tonbright on 2018/5/10.
//  Copyright © 2018年 tonbright. All rights reserved.
//

#import "TBRNameSettingC.h"
#import "UINavigationController+SXFullScreen.h"
#import "NetWorkRequest.h"
@interface TBRNameSettingC ()
@property (weak, nonatomic) IBOutlet UITextField *tf_name;

@end

@implementation TBRNameSettingC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
    
}

- (void)setupUI {
    //设置导航条
    [self setupNavItem];
    self.view.backgroundColor = [UIColor whiteColor];
    //添加tableView
}

- (void)setupNavItem {
    self.titleText = @"姓名设置";
    [self ISG_NavigationBarRightBarWithTitle:@"完成" andAction:@selector(finishBtnClick)];
    [self ISG_NavigationBarWithBackButtonTitle:nil leftImageNamed:nil andAction:@selector(backBtnClick)];
    self.sx_disableInteractivePop = YES;
}
- (IBAction)didClickBackBtn:(UIButton *)sender {
    [self backBtnClick];
}

- (void)backBtnClick {
    [self showBackBtnClickAlertShowMessage:nil block:^{
    }];
}

- (IBAction)finishBtnClick:(UIButton *)sender {
    [self finishBtnClick];
}


- (void)finishBtnClick {
    if ([HelpObject isBlankString:_tf_name.text]) {
        [self setNoticeText:@"请先填写姓名"];
        return;
    }
    //提交网络数据--------------
    __weak typeof(self) weakSelf = self;
    [self showFinishBtnClickAlertShowMessage:nil block:^{
        [weakSelf updateinfoMessage];
    }];
}



// MARK: - 上传个人信息-------
- (void)updateinfoMessage{
    [self progressHUDShowWithText:nil];
    __weak typeof(self) weakSelf = self;
    NSDictionary *dic = @{
                          @"updateuserid":[HelpObject changeNull:[AppSetting shareAppSetting].memberid],
                          @"oldupdatetime":[HelpObject changeNull:[AppSetting shareAppSetting].updatetime],
                          @"nickname":self.tf_name.text
                          };
    [NetWorkRequest postNetRequestData:UpdateMemberMessage parmeters:dic response:^(NSDictionary *response) {
        [weakSelf progressHUDHideImmediately];
        if (response) {
            //发送网络请求
            if (weakSelf.nameSettingCBlock) {
                weakSelf.nameSettingCBlock(weakSelf.tf_name.text);
                [weakSelf.navigationController popViewControllerAnimated:YES];
            }
        }
    } netError:^(NSError *error) {
        [weakSelf progressHUDHideImmediately];
    }];
}



- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.tf_name becomeFirstResponder];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.view endEditing:YES];
}

@end
